package com.example.CarManagement;

import com.example.CarManagement.enumPojo.DriverStatus;
import org.junit.jupiter.api.Test;

import java.util.*;

public class EnumDemo {
    private static final Set<Long> generatedIds = new HashSet<>();
    private static final Random random = new Random();

    public static synchronized long generateUniqueId() {
        long id;
        do {
            // 生成长度在2-6位的数字
            int length = random.nextInt(5) + 2; // 2-6位
            StringBuilder sb = new StringBuilder();

            // 第一位不能为0
            sb.append(random.nextInt(9) + 1);

            // 生成剩余位数
            for (int i = 1; i < length; i++) {
                sb.append(random.nextInt(10));
            }

            id = Long.parseLong(sb.toString());
        } while (generatedIds.contains(id));

        generatedIds.add(id);
        return id;
    }
    @Test
    void test(){
        // 生成10个唯一ID
        for (int i = 0; i < 10; i++) {
            System.out.println("Generated ID: " + generateUniqueId());
        }
    }
}
